package com.bjc.principle.flyweight;

import java.util.HashSet;
import java.util.Set;

/**
 * @program: DesignPattern
 * @description: 享元工厂
 * @author: bjc
 * @create: 2021-01-04 16:45
 */
public class BikeFlyWeightFactory {

    private static BikeFlyWeightFactory instance = new BikeFlyWeightFactory();

    private Set<BikeFlyWeight> pool = new HashSet<>();

    public static BikeFlyWeightFactory getInstance(){
        return instance;
    }

    private BikeFlyWeightFactory(){
        for (int i =0;i<2;i++){
            pool.add(new MoBikeFlyWeight(i+"号"));
        }
        System.out.println("size"+pool.size());
    }

    public BikeFlyWeight getBike(){
        for (BikeFlyWeight bike : pool){
            System.out.println(bike.getState());
            if (bike.getState()==0){
                return bike;
            }
        }
        return null;
    }
}
